<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>
        <a href="/">订单管理</a>
      </el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card class="box-card">
      <el-input
        style="width:400px"
        placeholder="请输入内容"
        class="input-with-select"
        v-model="queryData.query"
        clearable
        @change="getOrdersList"
      >
        <el-button slot="append" icon="el-icon-search" @click="getOrdersList"></el-button>
      </el-input>
      <!-- 表格 -->
      <el-table :data="ordersList" border>
        <!-- 表格里面索引列 -->
        <el-table-column type="index" label="#"></el-table-column>
        <!-- 表格里面数据渲染列 -->
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="order_pay" label="是否付款">
          <template slot-scope="scope">
            <el-tag size="mini" v-if="scope.row.order_pay==='1'">支付宝付款</el-tag>
            <el-tag size="mini" v-else-if="scope.row.order_pay==='2'">微信付款</el-tag>
            <el-tag size="mini" v-else-if="scope.row.order_pay==='3'">银行卡付款</el-tag>
            <el-tag size="mini" type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column prop="create_time" label="下单时间"></el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="editAdress"></el-button>
            <el-button
              type="success"
              icon="el-icon-location-outline"
              size="mini"
              @click="editProgress"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页功能 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryData.pagenum"
        :page-sizes="[2, 3, 5, 6]"
        :page-size="queryData.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
      <!-- 修改地址对话框 -->
      <el-dialog
        title="修改用户"
        :visible.sync="addressDialogVisible"
        width="30%"
        @close="closeAddressDialog"
      >
        <el-form
          :model="addressForm"
          :rules="addressFormRules"
          ref="addressFormRef"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-form-item label="请选择区域" prop="address1">
            <el-cascader
              clearable
              v-model="addressForm.address1"
              :options="cityData"
              :props="cascaderProps"
              @change="handleAddressChange"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="address2">
            <el-input v-model="addressForm.address2" clearable></el-input>
          </el-form-item>
        </el-form>
        <!-- 底部 -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="addressDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="addressDialogVisible = false">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 物流对话框 -->
      <el-dialog title="物流显示" :visible.sync="progressDialogVisible" width="50%">
        <!-- 时间线 -->
        <el-timeline>
    <el-timeline-item
      v-for="(activity, index) in timeLineList"
      :key="index"
      :timestamp="activity.time">
      {{activity.context}}
    </el-timeline-item>
  </el-timeline>
      </el-dialog>
    </el-card>
  </div>
</template>
<script>
import cityData from './citydata'
export default {
  data () {
    return {
      queryData: {
        query: '',
        pagenum: 1,
        pagesize: 2
      },
      ordersList: [],
      total: undefined,
      // 修改地址对话框
      addressDialogVisible: false,
      addressForm: {
        address1: [],
        address2: ''
      },
      addressFormRules: {},
      cascaderProps: {
        expandTrigger: 'hover',
        checkStrictly: true
      },
      cityData: cityData,
      // 物流数据
      progressDialogVisible: false,
      timeLineList: []
    }
  },
  mounted () {
    this.getOrdersList()
  },
  methods: {
    // 获取订单列表数据
    async getOrdersList () {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryData
      })
      if (res.meta.status !== 200) return this.$message.error('获取数据失败')
      this.ordersList = res.data.goods
      this.total = res.data.total
    },
    handleSizeChange (val) {
      this.queryData.pagesize = val
      this.getOrdersList()
    },
    handleCurrentChange (val) {
      this.queryData.pagenum = val
      this.getOrdersList()
    },
    editAdress () {
      this.addressDialogVisible = true
    },
    handleAddressChange () {},
    // 关闭对话框重置表单
    closeAddressDialog () {
      this.$refs.addressFormRef.resetFields()
    },
    // 物流
    async editProgress () {
      var id = 4307284002446
      const { data: res } = await this.$http.get('/kuaidi/' + id)
      if (res.meta.status !== 200) { return this.$message.error('物流信息获取失败') }
      console.log(res)
      this.timeLineList = res.data

      this.progressDialogVisible = true
    }
  }
}
</script>
<style scoped>
</style>
